﻿package com.alstudio.view.absadapter;

import java.util.ArrayList;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.module.xmpp.protocol.xmpp.data.ALPhoto;
import com.loovee.imaohu.R;

public class PhotoAdapter extends ViewAdapter {

	private ArrayList<ALPhoto> photos;

	private boolean isVauth = false;

	private boolean isMyIcon = false;

	public PhotoAdapter(ArrayList<ALPhoto> photos, boolean isMyIcon,
			boolean isVauth) {
		this.photos = photos;
		this.isVauth = isVauth;
		this.isMyIcon = isMyIcon;
	}

	/**
	 * @param isVauth the isVauth to set
	 */
	public void setVauth(boolean isVauth) {
		this.isVauth = isVauth;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.view.absadapter.ViewAdapter#getRealCount()
	 */
	@Override
	public int getRealCount() {
		// TODO Auto-generated method stub
		return photos.size();
	}

	@Override
	public int getCount() {
		return photos.size();
	}

	@Override
	public Object getItem(int position) {
		return photos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = ALLocalEnv.getLocalEnv().getGlobalLayoutInflater()
					.inflate(R.layout.photo_item, parent, false);
			viewHolder = new ViewHolder();

			viewHolder.hall_imageview = (ImageView) convertView
					.findViewById(R.id.view_photo);
			viewHolder.hall_textview = (TextView) convertView
					.findViewById(R.id.my_v_state);// V认证
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.hall_textview.setVisibility(View.GONE);

		if (photos.get(position).isVauth()) {
			viewHolder.hall_textview.setVisibility(View.VISIBLE);
			if (isVauth) {
				viewHolder.hall_textview
						.setBackgroundResource(R.drawable.photo_tip1);
			} else {
				if (isMyIcon) {
					viewHolder.hall_textview
							.setBackgroundResource(R.drawable.photo_tip2);
				}
			}
		} else {
			viewHolder.hall_textview.setVisibility(View.GONE);
		}

		ALPhoto photo = photos.get(position);
		if (!TextUtils.isEmpty(photo.getThumbnailFileid())) {
			ALLocalEnv.getLocalEnv().displayImagePluginServerlet(
					ALLocalEnv.getBareFileId(photo.getThumbnailFileid()),
					viewHolder.hall_imageview,
					ALLocalEnv.getLocalEnv().getRoundImageDisplayOption());
		}
		return convertView;

	}

	private class ViewHolder {
		public ImageView hall_imageview;
		public TextView hall_textview;

	}
}
